package model.address;

import java.util.ArrayList;
import java.util.List;

import model.ConfigData;
import model.database.CallStatus;
import model.database.ObjectDataProvider;
import model.database.QueryInstruction;
import model.posterminal.posterminalmodel.PosTerminalModel;

import org.simpleframework.xml.Attribute;
import org.simpleframework.xml.Element;
import org.simpleframework.xml.Root;

/*
 * Address class
 */
@Root(name = "address")
public class Address extends ObjectDataProvider {
	
	// object Id in database
	@Attribute
	(name = "id")
	long 	id 			= ConfigData.NOVALUELONG;
	
	// Address text title
	@Element(name = "addressname", required = false)
	String 	addressName	= ConfigData.STRINGNOVALUE;
	
	/**
	 * Get id of address in database
	 * @return
	 */
	public long getId() {
		return id;
	}
	
	/**
	 * Get title of address
	 * @return
	 */
	public String getAddressName() {
		return addressName;
	}
	
	/**
	 * Set title of address
	 * @param addressName
	 */
	public void setAddressName(String addressName) {
		this.addressName = addressName;
	}
	
	//Overrided toString method.
	@Override
	public String toString() {
		// TODO Auto-generated method stub
		return addressName;
	}
	
	/**
	 * Save object in database
	 * @throws Exception
	 */
	public void save() throws Exception {
		String storeProcedureName = "AddressSave";
		
		if (this.id == ConfigData.NOVALUELONG) {
			this.id = ((Address) this.sendObject2GetObject(this, this.getClass(), storeProcedureName)).getId();
		} 
		else {
			this.sendObject2GetObject(this, this.getClass(), storeProcedureName);
		}
		
	}
	
	/**
	 * Load all exist addresses
	 * @return
	 * @throws Exception
	 */
	public List<Address> getAllAddress() throws Exception {
		String storedProcedureName = "addressListLoad";
		ArrayList<Address> result = new ArrayList<Address>();

		result = (ArrayList<Address>) this.sendObject2GetListObject(this, this.getClass(), storedProcedureName);
		
		return result;
	}

}
